<!DOCTYPE html>
<html lang=zh>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="hexo-to-your-server原文(https:&#x2F;&#x2F;github.com&#x2F;lawler61&#x2F;hexo-to-server) 一、开始配置本地 node 环境 node下载 官网下载，可以的话推荐使用 nvm 安装  安装记得把目录改到其他盘，这里我具体是在 D:\programming\nodejs    打开cmd查看node安装情况 12node -vnpm -v   配置全局环境">
<meta property="og:type" content="article">
<meta property="og:title" content="hexo to your server">
<meta property="og:url" content="http://yoursite.com/2020/06/04/hexo-to-server/index.html">
<meta property="og:site_name" content="Sampson&#39;s blog">
<meta property="og:description" content="hexo-to-your-server原文(https:&#x2F;&#x2F;github.com&#x2F;lawler61&#x2F;hexo-to-server) 一、开始配置本地 node 环境 node下载 官网下载，可以的话推荐使用 nvm 安装  安装记得把目录改到其他盘，这里我具体是在 D:\programming\nodejs    打开cmd查看node安装情况 12node -vnpm -v   配置全局环境">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/node-path.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/env-node.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/env-path.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/test-hexo.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/npm-script.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/hexo-theme.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/npm-script-start.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/git-warning.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/git-clone.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/nginx-conf.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/nginx-user.jpg">
<meta property="og:image" content="http://yoursite.com/2020/06/04/hexo-to-server/config-deploy.jpg">
<meta property="article:published_time" content="2020-06-04T02:56:43.276Z">
<meta property="article:modified_time" content="2020-06-04T02:56:13.000Z">
<meta property="article:author" content="Sampson.Z">
<meta property="article:tag" content="Git">
<meta property="article:tag" content="hexo">
<meta property="article:tag" content="非原创">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://yoursite.com/2020/06/04/hexo-to-server/node-path.jpg">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>hexo to your server</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
      
<link rel="stylesheet" href="/css/rtl.css">

    
    <!-- rss -->
    
    
<meta name="generator" content="Hexo 4.2.1"><link rel="alternate" href="/atom.xml" title="Sampson's blog" type="application/atom+xml">
</head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/projects-url">项目</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/categories/">分类</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/2020/06/04/20200603%E4%B8%AA%E4%BA%BA%E6%97%A5%E5%BF%97%E8%AE%B0%E5%BD%95/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/2020/06/04/server/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=http://yoursite.com/2020/06/04/hexo-to-server/" target="_blank" rel="noopener"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=http://yoursite.com/2020/06/04/hexo-to-server/&text=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=http://yoursite.com/2020/06/04/hexo-to-server/&title=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=http://yoursite.com/2020/06/04/hexo-to-server/&is_video=false&description=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=hexo to your server&body=Check out this article: http://yoursite.com/2020/06/04/hexo-to-server/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=http://yoursite.com/2020/06/04/hexo-to-server/&title=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=http://yoursite.com/2020/06/04/hexo-to-server/&title=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=http://yoursite.com/2020/06/04/hexo-to-server/&title=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=http://yoursite.com/2020/06/04/hexo-to-server/&title=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=http://yoursite.com/2020/06/04/hexo-to-server/&name=hexo to your server&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=http://yoursite.com/2020/06/04/hexo-to-server/&t=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#hexo-to-your-server"><span class="toc-number">1.</span> <span class="toc-text">hexo-to-your-server</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、开始"><span class="toc-number">1.1.</span> <span class="toc-text">一、开始</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#配置本地-node-环境"><span class="toc-number">1.1.1.</span> <span class="toc-text">配置本地 node 环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#初始化hexo项目"><span class="toc-number">1.1.2.</span> <span class="toc-text">初始化hexo项目</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#git环境搭建"><span class="toc-number">1.1.3.</span> <span class="toc-text">git环境搭建</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三、服务器配置"><span class="toc-number">1.2.</span> <span class="toc-text">三、服务器配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#搭建远程Git私库"><span class="toc-number">1.2.1.</span> <span class="toc-text">搭建远程Git私库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#搭建nginx服务器"><span class="toc-number">1.2.2.</span> <span class="toc-text">搭建nginx服务器</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#四、发布"><span class="toc-number">1.3.</span> <span class="toc-text">四、发布</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#配置-config-yml文件"><span class="toc-number">1.3.1.</span> <span class="toc-text">配置_config.yml文件</span></a></li></ol></li></ol></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        hexo to your server
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">Sampson's blog</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2020-06-04T02:56:43.276Z" itemprop="datePublished">2020-06-04</time>
        
      
    </div>


      

      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/Git/" rel="tag">Git</a>, <a class="tag-link" href="/tags/hexo/" rel="tag">hexo</a>, <a class="tag-link" href="/tags/%E9%9D%9E%E5%8E%9F%E5%88%9B/" rel="tag">非原创</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h1 id="hexo-to-your-server"><a href="#hexo-to-your-server" class="headerlink" title="hexo-to-your-server"></a>hexo-to-your-server</h1><p>原文(<a href="https://github.com/lawler61/hexo-to-server" target="_blank" rel="noopener">https://github.com/lawler61/hexo-to-server</a>)</p>
<h2 id="一、开始"><a href="#一、开始" class="headerlink" title="一、开始"></a>一、开始</h2><h3 id="配置本地-node-环境"><a href="#配置本地-node-环境" class="headerlink" title="配置本地 node 环境"></a>配置本地 node 环境</h3><ol>
<li><p><code>node</code>下载 <a href="https://nodejs.org/zh-cn/download/" target="_blank" rel="noopener">官网下载</a>，可以的话推荐使用 <code>nvm</code> 安装</p>
</li>
<li><p>安装记得把目录改到其他盘，这里我具体是在 <code>D:\programming\nodejs</code></p>
</li>
</ol>
<p><img src="/2020/06/04/hexo-to-server/node-path.jpg" alt="node更换路径"></p>
<p>打开<code>cmd</code>查看<code>node</code>安装情况</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">node -v</span><br><span class="line">npm -v</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>配置全局环境</li>
</ol>
<p>进入安装目录，创建文件夹<code>node_global</code>和<code>node_cache</code> 并执行</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm config <span class="built_in">set</span> prefix <span class="string">"D:\programming\nodejs\node_global"</span></span><br><span class="line">npm config <span class="built_in">set</span> cache <span class="string">"D:\programming\nodejs\node_cache"</span></span><br></pre></td></tr></table></figure>

<p>环境配置：新增环境变量<code>NODE_PATH</code>和添加<code>Path</code>，两个值都为 <code>D:\programming\nodejs\node_global</code></p>
<p><img src="/2020/06/04/hexo-to-server/env-node.jpg" alt="node更换路径"></p>
<p><img src="/2020/06/04/hexo-to-server/env-path.jpg" alt="node更换路径"></p>
<ol start="4">
<li>安装<code>hexo-cli</code></li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm i hexo-cli -g</span><br><span class="line">hexo</span><br></pre></td></tr></table></figure>

<p>如果显示下面情况，恭喜你成功全局模块调用</p>
<p><img src="/2020/06/04/hexo-to-server/test-hexo.jpg" alt="node更换路径"></p>
<ol start="5">
<li><p>如果出现<code>命令未找到，或不是可执行程序</code>，别着急！<strong>先仔细重复 3-4 步</strong>，一般是能够给解决的，如果实在是不能解决，往后看</p>
</li>
<li><p>随便找个地方初始化文件，执行如下命令：</p>
</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mkdir hexo-blog</span><br><span class="line"><span class="built_in">cd</span> hexo-blog &amp;&amp; npm init -y</span><br></pre></td></tr></table></figure>

<p>现在有 3 种解决方法，<strong>任选其一</strong></p>
<ul>
<li>法 1：检查全局目录是否的<code>hexo</code>模块，执行如下命令：</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">D:\programming\nodejs\node_global\hexo</span><br></pre></td></tr></table></figure>

<ul>
<li>法 2：如果觉得每次加前缀麻烦，使用<code>link</code>命令链接</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm link hexo</span><br></pre></td></tr></table></figure>

<p>package.json 中新建脚本如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm run hexo</span><br></pre></td></tr></table></figure>

<p><img src="/2020/06/04/hexo-to-server/npm-script.jpg" alt="新建npm脚本"></p>
<ul>
<li>法 3：你还可以直接在<code>hexo-blog</code>中下载</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">npm i hexo-cli</span><br><span class="line">npm run hexo （还是要在package.json中新建脚本）</span><br></pre></td></tr></table></figure>

<h3 id="初始化hexo项目"><a href="#初始化hexo项目" class="headerlink" title="初始化hexo项目"></a>初始化<code>hexo</code>项目</h3><ol>
<li>如果是按照上一节步骤 4 过来的，则在<code>hexo-blog</code>文件下初始化</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">hexo init myblog &amp;&amp; <span class="built_in">cd</span> myblog</span><br><span class="line">npm i</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>下载主题</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> https://github.com/iissnan/hexo-theme-next themes/next</span><br></pre></td></tr></table></figure>

<p>在<strong>本地配置文件</strong>中设置<code>theme</code>属性</p>
<p><img src="/2020/06/04/hexo-to-server/hexo-theme.jpg" alt="添加next主题"></p>
<ol start="3">
<li>本地执行<code>hexo</code>项目，添加<code>start</code>脚本</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm start</span><br></pre></td></tr></table></figure>

<p><img src="/2020/06/04/hexo-to-server/npm-script-start.jpg" alt="新建npm-start脚本"></p>
<p>打开 <a href="http://localhost:4000" target="_blank" rel="noopener">http://localhost:4000</a> 验证效果吧</p>
<h3 id="git环境搭建"><a href="#git环境搭建" class="headerlink" title="git环境搭建"></a><code>git</code>环境搭建</h3><ol>
<li><p><code>git</code>安装：<a href="https://git-scm.com/downloads" target="_blank" rel="noopener">官网下载</a></p>
</li>
<li><p>生成<code>ssh</code>认证，执行如下命令</p>
</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name <span class="string">"yourname"</span></span><br><span class="line">git config --global user.email youremail@example.com</span><br><span class="line">ssh-keygen -t rsa -C <span class="string">"youremail@example.com"</span></span><br><span class="line">git config --global core.autocrlf <span class="literal">false</span>  // 禁用自动转换，这个不设置后面上传时会出现警告，如下</span><br></pre></td></tr></table></figure>

<p><img src="/2020/06/04/hexo-to-server/git-warning.jpg" alt="git警告"></p>
<p>最后获取到的<code>ssh</code>认证在<code>C:\Users\yourname\.ssh</code>中</p>
<hr>
<h2 id="三、服务器配置"><a href="#三、服务器配置" class="headerlink" title="三、服务器配置"></a>三、服务器配置</h2><h3 id="搭建远程Git私库"><a href="#搭建远程Git私库" class="headerlink" title="搭建远程Git私库"></a>搭建远程<code>Git</code>私库</h3><ol>
<li><p>登录到远程服务器，推荐使用<code>Xshell 5</code></p>
</li>
<li><p>安装 git</p>
</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git --version // 如无，则安装</span><br><span class="line">yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel</span><br><span class="line">yum install -y git</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>创建用户并配置其仓库</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">useradd git</span><br><span class="line">passwd git // 设置密码</span><br><span class="line">su git // 这步很重要，不切换用户后面会很麻烦</span><br><span class="line"><span class="built_in">cd</span> /home/git/</span><br><span class="line">mkdir -p projects/blog // 项目存在的真实目录</span><br><span class="line">mkdir repos &amp;&amp; <span class="built_in">cd</span> repos</span><br><span class="line">git init --bare blog.git // 创建一个裸露的仓库</span><br><span class="line"><span class="built_in">cd</span> blog.git/hooks</span><br><span class="line">vi post-receive // 创建 hook 钩子函数，输入了内容如下</span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/sh</span></span><br><span class="line">git --work-tree=/home/git/projects/blog --git-dir=/home/git/repos/blog.git checkout -f</span><br></pre></td></tr></table></figure>

<p>添加完毕后修改权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">chmod +x post-receive</span><br><span class="line"><span class="built_in">exit</span> // 退出到 root 登录</span><br><span class="line">chown -R git:git /home/git/repos/blog.git // 添加权限</span><br></pre></td></tr></table></figure>

<ol start="4">
<li>测试<code>git仓库</code>是否可用，另找空白文件夹</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> git@server_ip:/home/git/repos/blog.git</span><br></pre></td></tr></table></figure>

<p>如果能把空仓库拉下来，就说明 git 仓库搭建成功了</p>
<p><img src="/2020/06/04/hexo-to-server/git-clone.jpg" alt="git仓库测试"></p>
<ol start="5">
<li>建立<code>ssh</code>信任关系，在<strong>本地电脑</strong></li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ssh-copy-id -i C:/Users/yourname/.ssh/id_rsa.pub git@server_ip</span><br><span class="line">ssh git@server_ip // 测试能否登录</span><br></pre></td></tr></table></figure>

<p><strong>注</strong>：此时的 ssh 登录 git 用户不需要密码！否则就<strong>有错</strong>，请仔细重复步骤 3-5</p>
<ol start="6">
<li>为了安全起见禁用 git 用户的 shell 登录权限，从而只能用 git clone，git push 等登录</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">cat /etc/shells // 查看 git-shell 是否在登录方式里面</span><br><span class="line"><span class="built_in">which</span> git-shell // 查看是否安装</span><br><span class="line">vi /etc/shells</span><br><span class="line">添加上2步显示出来的路劲，通常在 /usr/bin/git-shell</span><br></pre></td></tr></table></figure>

<p>修改<code>/etc/passwd</code>中的权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">// 将原来的</span><br><span class="line">git:x:1000:1000::/home/git:/bin/bash</span><br><span class="line"></span><br><span class="line">// 修改为</span><br><span class="line">git:x:1000:1000:,,,:/home/git:/usr/bin/git-shell</span><br></pre></td></tr></table></figure>

<h3 id="搭建nginx服务器"><a href="#搭建nginx服务器" class="headerlink" title="搭建nginx服务器"></a>搭建<code>nginx</code>服务器</h3><ol>
<li>下载并安装<code>nginx</code></li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /usr/<span class="built_in">local</span>/src</span><br><span class="line">wget http://nginx.org/download/nginx-1.15.2.tar.gz</span><br><span class="line">tar xzvf nginx-1.15.2.tar.gz</span><br><span class="line"><span class="built_in">cd</span> nginx-1.15.2</span><br><span class="line">./configure // 如果后面还想要配置 SSL 协议，就执行后面一句！</span><br><span class="line">./configure --prefix=/usr/<span class="built_in">local</span>/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module</span><br><span class="line">make &amp;&amp; make install</span><br><span class="line"><span class="built_in">alias</span> nginx=<span class="string">'/usr/local/nginx/sbin/nginx'</span> // 为 nginx 取别名，后面可直接用</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>配置<code>nginx</code>文件</li>
</ol>
<p>先启动是否安装成功</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nginx // 直接来！浏览器查看 server_ip，默认是 80 端口</span><br></pre></td></tr></table></figure>

<p>修改配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">nginx -s stop // 先停止nginx</span><br><span class="line"><span class="built_in">cd</span> /usr/<span class="built_in">local</span>/nginx/conf</span><br><span class="line">vi nginx.conf</span><br><span class="line">修改 root 解析路径，如下图</span><br><span class="line">同时将 user 改为 root 如下图，不然nginx无法访问 /home/git/project/blog</span><br><span class="line">nginx -s reload</span><br></pre></td></tr></table></figure>

<p><img src="/2020/06/04/hexo-to-server/nginx-conf.jpg" alt="修改nginx配置"></p>
<p><img src="/2020/06/04/hexo-to-server/nginx-user.jpg" alt="修改nginx user"></p>
<hr>
<h2 id="四、发布"><a href="#四、发布" class="headerlink" title="四、发布"></a>四、发布</h2><p>至此我们就把本地和服务器的环境全部搭建完成，现在利用 hexo 配置文件进行链接</p>
<h3 id="配置-config-yml文件"><a href="#配置-config-yml文件" class="headerlink" title="配置_config.yml文件"></a>配置<code>_config.yml</code>文件</h3><ol>
<li>编辑 _config.yml 的 deploy 属性</li>
</ol>
<p><img src="/2020/06/04/hexo-to-server/config-deploy.jpg" alt="编辑本地deploy"></p>
<ol start="2">
<li>在 package.json 中添加 npm 脚本</li>
</ol>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">"scripts": &#123;</span><br><span class="line">  "deploy": "hexo clean &amp;&amp; hexo g -d",</span><br><span class="line">  "start": "hexo clean &amp;&amp; hexo g &amp;&amp; hexo s"</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>链接！这下在本地调试就用<code>npm start</code>，调试好了就上传到服务器，美滋滋~快通过你的服务器 ip 访问吧</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm run deploy</span><br></pre></td></tr></table></figure>

  </div>
</article>












		<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
		<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
		<!--<script src="//cdn.jsdelivr.net/npm/leancloud-storage@latest/dist/av-min.js"></script>
    <script src='//cdn.jsdelivr.net/npm/valine@latest/dist/Valine.min.js'></script>-->
	<div id="vcomments"></div>
	<script>
		var notify = false == true ? true : false;
		var verify = false == true ? true : false;
		var visitor = true == true ? true : false;
  new Valine({
      el: '#vcomments',
				notify: notify,
				verify: verify,
    	app_id: 'MyX4PiXsizWYy8EuLEFEE05g-MdYXbMMI',
      app_key: 'rvmEQ2Sd345um4vPgXbnKbje',
			lang: 'en',
			placeholder: 'ヾﾉ≧∀≦)o快来评论一下吧!',
			avatar: 'monsterid',
			pageSize: 10,
			visitor: visitor
        });
    </script>






        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/projects-url">项目</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/categories/">分类</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#hexo-to-your-server"><span class="toc-number">1.</span> <span class="toc-text">hexo-to-your-server</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、开始"><span class="toc-number">1.1.</span> <span class="toc-text">一、开始</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#配置本地-node-环境"><span class="toc-number">1.1.1.</span> <span class="toc-text">配置本地 node 环境</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#初始化hexo项目"><span class="toc-number">1.1.2.</span> <span class="toc-text">初始化hexo项目</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#git环境搭建"><span class="toc-number">1.1.3.</span> <span class="toc-text">git环境搭建</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三、服务器配置"><span class="toc-number">1.2.</span> <span class="toc-text">三、服务器配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#搭建远程Git私库"><span class="toc-number">1.2.1.</span> <span class="toc-text">搭建远程Git私库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#搭建nginx服务器"><span class="toc-number">1.2.2.</span> <span class="toc-text">搭建nginx服务器</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#四、发布"><span class="toc-number">1.3.</span> <span class="toc-text">四、发布</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#配置-config-yml文件"><span class="toc-number">1.3.1.</span> <span class="toc-text">配置_config.yml文件</span></a></li></ol></li></ol></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=http://yoursite.com/2020/06/04/hexo-to-server/" target="_blank" rel="noopener"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=http://yoursite.com/2020/06/04/hexo-to-server/&text=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=http://yoursite.com/2020/06/04/hexo-to-server/&title=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=http://yoursite.com/2020/06/04/hexo-to-server/&is_video=false&description=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=hexo to your server&body=Check out this article: http://yoursite.com/2020/06/04/hexo-to-server/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=http://yoursite.com/2020/06/04/hexo-to-server/&title=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=http://yoursite.com/2020/06/04/hexo-to-server/&title=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=http://yoursite.com/2020/06/04/hexo-to-server/&title=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=http://yoursite.com/2020/06/04/hexo-to-server/&title=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=http://yoursite.com/2020/06/04/hexo-to-server/&name=hexo to your server&description=" target="_blank" rel="noopener"><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://news.ycombinator.com/submitlink?u=http://yoursite.com/2020/06/04/hexo-to-server/&t=hexo to your server" target="_blank" rel="noopener"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
    
    
    2016-2020
    Sampson.Z
<img src="https://static.dy208.cn/o_1dfilp8ruo521thr1hvf18ji17soa.png">
<a href="http://www.beian.miit.gov.cn/"  style="color:#f72b07" target="_blank">粤ICP备19066509号</a>

  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/projects-url">项目</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/categories/">分类</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
    <!-- styles -->

<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">


<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">


    <!-- jquery -->

<script src="/lib/jquery/jquery.min.js"></script>


<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>

<!-- clipboard -->

  
<script src="/lib/clipboard/clipboard.min.js"></script>

  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"复制到粘贴板!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "复制成功!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

<!-- Disqus Comments -->


</body>
</html>
